package com.bigdata.service.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.bigdata.common.annotation.RepeatSubmit;
import com.bigdata.common.annotation.Log;
import com.bigdata.common.core.controller.BaseController;
import com.bigdata.common.core.domain.PageQuery;
import com.bigdata.common.core.domain.R;
import com.bigdata.common.core.validate.AddGroup;
import com.bigdata.common.core.validate.EditGroup;
import com.bigdata.common.core.validate.QueryGroup;
import com.bigdata.common.enums.BusinessType;
import com.bigdata.common.utils.poi.ExcelUtil;
import com.bigdata.service.domain.vo.UserCollectionsVo;
import com.bigdata.service.domain.bo.UserCollectionsBo;
import com.bigdata.service.service.IUserCollectionsService;
import com.bigdata.common.core.page.TableDataInfo;

/**
 * 用户收藏
 *
 * @author ruoyi
 * @date 2025-07-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/service/collections")
public class UserCollectionsController extends BaseController {

    private final IUserCollectionsService iUserCollectionsService;

//    /**
//     * 查询用户收藏列表
//     */
//    @SaCheckPermission("service:collections:list")
//    @GetMapping("/list")
//    public TableDataInfo<UserCollectionsVo> list(UserCollectionsBo bo, PageQuery pageQuery) {
//        return iUserCollectionsService.selectUserCollectionsPageList(bo, pageQuery);
//    }

    /**
     * 导出用户收藏列表
     */
    @SaCheckPermission("service:collections:export")
    @Log(title = "用户收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(UserCollectionsBo bo, HttpServletResponse response) {
        List<UserCollectionsVo> list = iUserCollectionsService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户收藏", UserCollectionsVo.class, response);
    }

    /**
     * 获取用户收藏详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("service:collections:query")
    @GetMapping("/{id}")
    public R<UserCollectionsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iUserCollectionsService.queryById(id));
    }

    /**
     * 新增用户收藏
     */
    @SaCheckPermission("service:collections:add")
    @Log(title = "用户收藏", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody UserCollectionsBo bo) {
        return toAjax(iUserCollectionsService.insertByBo(bo));
    }

    /**
     * 修改用户收藏
     */
    @SaCheckPermission("service:collections:edit")
    @Log(title = "用户收藏", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody UserCollectionsBo bo) {
        return toAjax(iUserCollectionsService.updateByBo(bo));
    }

    /**
     * 删除用户收藏
     *
     * @param ids 主键串
     */
    @SaCheckPermission("service:collections:remove")
    @Log(title = "用户收藏", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iUserCollectionsService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
